package com.longdaji.decoration.ui.activitiesOfMine.balance;

import com.longdaji.decoration.base.RxPresenter;
import com.longdaji.decoration.bean.Account;
import com.longdaji.decoration.bean.Balance;
import com.longdaji.decoration.data.DataManager;
import com.longdaji.decoration.data.network.CommonSubscriber;
import com.longdaji.decoration.utils.LogUtil;
import com.longdaji.decoration.utils.RxUtil;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Kanade on 2018/5/21 0021.
 */

public class BalancePresenter extends RxPresenter<BalanceContract.IView> implements BalanceContract.IPresenter {
    private DataManager mDataManager;

    @Inject
    public BalancePresenter(DataManager dataManager) {
        this.mDataManager = dataManager;
    }

    @Override
    public void doInitData(int type, int pageNo, int pageSize) {
        addSubscribe(mDataManager.doGetBalanceDetailApi(Account.getInstance().getUserid(), type, pageNo, pageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(RxUtil.<Balance>handleResult())
                .subscribeWith(new CommonSubscriber<Balance>() {
                    @Override
                    public void onSuccess(Balance balance) {
                        LogUtil.i("success doGetBalanceDetailApi: " + balance.getRecords().size());
                        mView.showInitBalanceDetail(balance);
                    }

                    @Override
                    public void onFailed(String msg) {
                        LogUtil.i("fail doGetBalanceDetailApi: " + msg);
                    }
                }));
    }
}
